package com.shanzmoo.merchant.manage.api.web.sys;

import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.core.domain.dto.SysMenuSaveDTO;
import com.shanzmoo.core.domain.dto.SysMenuUpdateDTO;
import com.shanzmoo.core.domain.vo.AuthMenuRouterVO;
import com.shanzmoo.core.domain.vo.MenuTreeVO;
import com.shanzmoo.merchant.manage.api.manager.SysMenuManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 前端控制器
 *
 * @author： Gzhao 2021/3/28
 */
@Api(tags = "系统管理--菜单")
@RestController
@RequiredArgsConstructor
@RequestMapping("/sys-menu")
public class SysMenuController {

    private final SysMenuManager sysMenuManager;

    @ApiOperation(value = "获取用户菜单权限")
    @GetMapping("/auth-list")
    public SHttpResponse<AuthMenuRouterVO> getAuthList(@RequestParam Integer id) {
        AuthMenuRouterVO menuRouterVO = sysMenuManager.getAuthListByUserId(id);
        return SHttpResponse.ok(menuRouterVO);
    }

    @ApiOperation(value = "所有菜单树")
    @GetMapping("/all-tree")
    public SHttpResponse<List<MenuTreeVO>> getAllTree() {
        List<MenuTreeVO> treeList = sysMenuManager.getAllTree();
        return SHttpResponse.ok(treeList);
    }

    @ApiOperation(value = "添加菜单")
    @PostMapping("/add")
    public SHttpResponse<Boolean> add(@Valid @RequestBody SysMenuSaveDTO saveDto) {
        sysMenuManager.save(saveDto);
        return SHttpResponse.ok();
    }

    @ApiOperation(value = "修改菜单")
    @PostMapping("/update")
    public SHttpResponse<Boolean> add(@Valid @RequestBody SysMenuUpdateDTO updateDto) {
        sysMenuManager.update(updateDto);
        return SHttpResponse.ok();
    }

    @ApiOperation(value = "删除菜单")
    @GetMapping("/delete")
    public SHttpResponse<Boolean> delete(@RequestParam Integer menuId) {
        sysMenuManager.delete(menuId);
        return SHttpResponse.ok();
    }
}
